﻿using Microsoft.Extensions.Configuration;
using Quantum.RabbitMq;

namespace SimpleRabbitMqServer
{
    class MyServerStartup : ServerStartup
    {
        private static Replier replier;
        protected override void ConfigureReplier(RabbitMqReplierBuilder builder)
        {
            replier = new Replier(x =>
            {
                var n = int.Parse(x);
                var result = fib(n);
                return result.ToString();
            });

            var conn = replier.Connect("localhost");
            if (conn)
            {
                builder.AddReplier(replier);
            }
            base.ConfigureReplier(builder);
        }

        private static int fib(int n)
        {
            if (n == 0 || n == 1)
            {
                return n;
            }

            return fib(n - 1) + fib(n - 2);
        }

    }
}
